var loadDataUrl = '/ajax/more.html'; // 获取更多数据URL

var $document = $(document);
var docHeight = document.documentElement.offsetHeight;
var winHeight = window.screen.height;

var getItem = function(data){
    return '<li>'+
        '<a href="/detail/?productId='+ data.id +'" class="lnk">'+
            '<div class="img"><img src="'+ data.img +'"></div><div class="tit">'+ data.title +'</div>'+
        '</a>'+
        '<div class="process">'+
            '<div class="desc">揭晓进度<span>'+ data.process +'</span></div>'+
            '<div class="bar"><span style="width:'+ data.process +'"></span></div>'+
        '</div>'+
    '</li>';
};

var loadMore = function(){
    loadMore.loading = 1;
    $('.loading-holder').show();
    $.get(loadDataUrl, function(data){
        if(data.retcode == 0){
            // 成功取到数据
            // data:{retcode:0,retdesc:"拉取数据成功",result:[{img:'url.jpg',title:'','process':'35%',id: 123}]}
            var htm = '';
            $.each(data.result,function(){
                htm += getItem(this);
            });
            $('.good-list').append(htm);
        }else{
            console.log(data.retdesc);
        }
        $('.loading-holder').hide();
        loadMore.loading = 0;
    });
};

$('#tabs span').on('click',function(){
    var type = this.getAttribute('type'); // hot: 人气, new:最新
    $('#tabs span').removeClass('cur');
    this.className = 'cur';

    // todo 切换标签后的操作
    console.log(type);
});

$('body').dropload({
    scrollArea: window,
    loadUpFn: function(me){
        location.reload();
    },
    domUp: {
        domRefresh: '<div class="dropload-refresh">下拉刷新</div>',
        domUpdate : '<div class="dropload-update">释放更新</div>'
    }
});


$document.on('scroll',function(){
    docHeight - winHeight - document.body.scrollTop < 150 && !loadMore.loading && loadMore();
});